package demo.practice.leetcode_eveyday;

import java.util.HashMap;
import java.util.Map;

public class P205 {

    public static void main(String[] args) {
        /**
         * "egg"
         * "add"
         */
        P205 p205= new P205();
        p205.isIsomorphic("egg","add");
    }

    public boolean isIsomorphic(String s, String t) {
            //egg   add
            //foo   bar
        if(s==null || t==null)
            return s==t;

        if(s.length()!=t.length())
            return false;

        Map<Character,Character> map= new HashMap<>();
        Map<Character,Character> map1= new HashMap<>();
        for(int i=0;i<s.length();i++){
            char c = t.charAt(i);
            char c1 = s.charAt(i);
            if(map.get(c)==null){
                if(map1.get(c1)!=null )
                    return false;
                else{
                    map.put(c,c1);
                    map1.put(c1,c);
                }
            }

            if(map.get(c)!= c1)
                return false;

           /* if(map.get(c)==null && map1.get(c1)==null){
                map.put(c,c1);
                map1.put(c1,c);
            }else{
                if(map.get(c)==null && map1.get(c1)!=null ){
                    return false;
                }

                if(map.get(c)!= c1)
                    return false;
            }*/
        }
        return true;
    }

}
